Imports System
Imports System.Collections.Generic
Imports ASPNET.StarterKit.DataAccessLayer

Namespace ASPNET.StarterKit.BusinessLogicLayer

	Public Class UserReport

		Private _ActualDuration As Decimal
		Private _CategoryId As Integer
		Private _UserName As String

		Public Sub New(ByVal reportActualDuration As Decimal, ByVal reportCategoryId As Integer, ByVal reportUserName As String)

			If reportCategoryId <= DefaultValues.GetCategoryIdMinValue() Then
				Throw (New ArgumentOutOfRangeException("categoryId"))
			End If

			If String.IsNullOrEmpty(reportUserName) Then
				Throw (New NullReferenceException("userName"))
			End If

			Me._ActualDuration = reportActualDuration
			Me._CategoryId = reportCategoryId
			Me._UserName = reportUserName

		End Sub

		Public ReadOnly Property ActualDuration() As Decimal

			Get
				Return Me._ActualDuration
			End Get

		End Property

		Public ReadOnly Property CategoryId() As Integer

			Get
				Return Me._CategoryId
			End Get

		End Property

		Public ReadOnly Property UserName() As String

			Get
				If String.IsNullOrEmpty(Me._UserName) Then
					Return String.Empty
				Else
					Return Me._UserName
				End If
			End Get

		End Property

		Public Shared Function GetUserReportsByCategoryId(ByVal CategoryId As Integer) As List(Of UserReport)

			If CategoryId <= DefaultValues.GetCategoryIdMinValue() Then
				Return New List(Of UserReport)()
			End If

			Dim DALLayer As DataAccess = DataAccessHelper.GetDataAccess()
			Return DataAccessHelper.GetDataAccess().GetUserReportsByCategoryId(CategoryId)

		End Function

		Public Shared Function GetUserReportsByProjectId(ByVal projectId As Integer) As List(Of UserReport)

			If projectId <= DefaultValues.GetProjectIdMinValue() Then
				Return New List(Of UserReport)()
			End If

			Return DataAccessHelper.GetDataAccess().GetUserReportsByProjectId(projectId)

		End Function

		Public Shared Function GetUserReportsByProjectIds(ByVal ProjectIds As String) As List(Of UserReport)

			If String.IsNullOrEmpty(ProjectIds) Then
				Return New List(Of UserReport)()
			End If

			Dim separator As Char() = New Char() {","c}
			Dim substrings As String() = ProjectIds.Split(separator)
			Dim list As New List(Of UserReport)()

			For Each str As String In substrings
				If Not String.IsNullOrEmpty(str) Then
					Dim id As Integer = Convert.ToInt32(str)
					Dim tempList As List(Of UserReport) = UserReport.GetUserReportsByProjectId(id)
					For Each userReport As UserReport In tempList
						list.Add(userReport)
					Next userReport
				End If
			Next str

			Return list

		End Function

	End Class

End Namespace
